home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / Presentations / STL & Modern C++ / STL4.cp < prev    next >
Encoding:
Text File  |  1999-06-25  |  1020 b   |  41 lines  |  [TEXT/CWIE]

  1. // STL4.cp
  2. #include <iostream>
  3. #include <set>
  4.  
  5. int main()
  6. {
  7.     typedef    std::set<char> MySet;
  8.     typedef    std::multiset<char> MyMultiSet;
  9.     std::ostream_iterator<char>    out(std::cout);
  10.     std::string    start("sleep is a poor substitute for caffeine");
  11.     MySet    s(start.begin(), start.end());
  12.     MyMultiSet    ms;
  13.     ms.insert(start.begin(), start.end());
  14.  
  15.     std::cout << "      start: ";
  16.     std::copy(s.begin(), s.end(), out);
  17.     std::cout << "\n      start: ";
  18.     std::copy(ms.begin(), ms.end(), out);
  19.  
  20.     MySet::iterator    si1, si2;
  21.     MyMultiSet::iterator    msi1, msi2;
  22.     si1 = s.lower_bound('b');
  23.     si2 = s.upper_bound('s');
  24.     s.erase(' ');
  25.     s.erase(si1, si2);
  26.     msi1 = ms.lower_bound('b');
  27.     msi2 = ms.upper_bound('s');
  28.     ms.erase(' ');
  29.     ms.erase(msi1, msi2);
  30.  
  31.     std::cout << "\nremoved b-s: ";
  32.     std::copy(s.begin(), s.end(), out);
  33.     std::cout << "\nremoved b-s: ";
  34.     std::copy(ms.begin(), ms.end(), out);
  35.     std::cout << "\n";
  36. }
  37. //       start:  abcefilnoprstu
  38. //       start:       aabceeeeefffiiilnooopprrsssstttuu
  39. // removed b-s: atu
  40. // removed b-s: aatttuu
  41.